package com.lancoo.znbkxx.teacher.aibkTestCoach.paperToPersonalAnalysis.aibkAnalysisTKT

import com.lancoo.znbkxx.teacher.aibkTestCoach.paperToPersonalAnalysis.AnalysisInforIndexHelp
import com.lancoo.znbkxx.teacher.aibkTestCoach.paperToPersonalAnalysis.AnalysisInforIndexHelp.getChildListBean
import android.animation.ObjectAnimator
import android.content.Context
import android.graphics.Bitmap
import android.os.Handler
import android.util.DisplayMetrics
import android.util.Log
import android.view.MotionEvent
import android.view.View
import android.view.WindowManager
import android.webkit.JavascriptInterface
import android.webkit.ValueCallback
import android.webkit.WebView
import android.webkit.WebViewClient
import androidx.appcompat.app.AppCompatActivity
import com.bumptech.glide.Glide
import com.bumptech.glide.request.target.SimpleTarget
import com.bumptech.glide.request.transition.Transition
import com.lancoo.znbkxx.teacher.Ext
import com.lancoo.znbkxx.teacher.R
import com.lancoo.znbkxx.teacher.aibkTestCoach.aibkDialog.ShowDialogTools
import com.lancoo.znbkxx.teacher.aibkTestCoach.aibkTools.LancooMethod
import com.lancoo.znbkxx.teacher.aibkTestCoach.auidoPlayer.AudioPlayer
import com.lancoo.znbkxx.teacher.aibkTestCoach.kBase.KBaseFragment
import com.lancoo.znbkxx.teacher.aibkTestCoach.networkRequest.entity.PaperPerAnalysisInfor
import com.lancoo.znbkxx.teacher.utils.DensityUtils
import com.lancoo.znbkxx.teacher.utils.WebStyleUtils
import com.lancoo.znbkxx.teacher.widget.KWebView
import kotlinx.android.synthetic.main.aibk_fragment_model_tkt.view.*
import kotlinx.android.synthetic.main.aibk_include_article_view.view.*
import kotlinx.android.synthetic.main.aibk_include_parent_audioplayer_a.view.*
import kotlinx.android.synthetic.main.aibk_include_ques_assessment.view.*
import kotlinx.android.synthetic.main.aibk_include_ques_web_tkt_ask_view.view.*
import kotlinx.android.synthetic.main.aibk_include_question_information_view.view.*
import java.text.SimpleDateFormat
import java.util.*

class AnalysisFragmentTkt(
        val activity: AppCompatActivity,
        val paperPerAnalysisInfor: PaperPerAnalysisInfor,
        val index_A: Int,
        val index_B: Int
) : KBaseFragment(), View.OnClickListener {

    private var rootView: View? = null
    private var isAddView = false
    private var childVpPosition = 0
    private var jumpSortIndex = ""
    private var scale = 0f
    private var current_Y = 0
    private var last_Y = 0
    private var screenWidth = 0

    override fun createLayout(): Int {
        return R.layout.aibk_fragment_model_tkt
    }

    override fun initView(view: View?) {
        screenWidth = DensityUtils.px2dp(activity,DensityUtils.getScreenWidth(activity).toFloat())
        Log.e("getScreenWidthAA", "=========获取屏幕宽度============" + screenWidth)
        scale = resources.displayMetrics.density
        rootView = view
        rootView!!.RlAudioPlayer.visibility = View.GONE
        rootView!!.RlArticleView.visibility = View.GONE
        rootView!!.IvPlayOrPause.setOnClickListener(this)
        rootView!!.IBtnArticle.visibility = View.GONE

        showQuestionView()
    }

    /*
    * 显示试题内容
    * */
    private fun showQuestionView() {

        //是否显示来源
        var resource = paperPerAnalysisInfor.TypeList[index_A].QuesDetailList[index_B].Resource
        if (resource.isEmpty()) {
            rootView!!.IncludeQuesInformationView.visibility = View.GONE
        } else {
            rootView!!.IncludeQuesInformationView.visibility = View.VISIBLE
            rootView!!.IncludeQuesInformationView.TvSourceFrom.text = "来源: $resource"
            //隐藏试题准确率
            rootView!!.IncludeQuesInformationView.TvScoreRate.visibility = View.GONE
        }

        //隐藏单题评估系数
        rootView!!.RlQuesAssessment.visibility = View.GONE

        //是否需要加载听力音频
        val typeNo = paperPerAnalysisInfor.TypeList[index_A].QuesDetailList[index_B].TypeNo
        if (typeNo == "S") {//听力填空
            var timeLength = paperPerAnalysisInfor.TypeList[index_A].QuesDetailList[index_B].QuesAudio.TimeLength
            val format = SimpleDateFormat("mm:ss", Locale.CHINA)
            rootView!!.TvAudioTotalTime.text = format.format(timeLength * 1000)
            rootView!!.RlAudioPlayer.visibility = View.VISIBLE
        } else {
            rootView!!.RlAudioPlayer.visibility = View.GONE
        }
        //加载题干内容
        var ask = ""
        var quesBody = paperPerAnalysisInfor.TypeList[index_A].QuesDetailList[index_B].QuesBody
        if (typeNo == "S") {//听力填空
            val childListSize = paperPerAnalysisInfor.TypeList[index_A].QuesDetailList[index_B].ChildList.size
            for (c in 0 until childListSize) {
                val sortIndex = getChildListBean(paperPerAnalysisInfor, index_A, index_B, c).ItemList[0].SortIndex
                val sortIndexType = getChildListBean(paperPerAnalysisInfor, index_A, index_B, c).SortIndexType
                val childAsk = getChildListBean(paperPerAnalysisInfor, index_A, index_B, c).ChildAsk
                if (sortIndexType == 0) {
                    if(quesBody.isEmpty()){
                        if(ask.isEmpty()) {
                            ask = "$sortIndex. $childAsk" + getHtmlAnalysisSingle(c)
                        }else{
                            ask = "$ask<br>$sortIndex. $childAsk" + getHtmlAnalysisSingle(c)
                        }
                    }else{
                        ask = quesBody + "<br>" + sortIndex + ". " + childAsk + getHtmlAnalysisSingle(c)
                    }
                } else if (sortIndexType == 1) {
                    ask = quesBody +"<br>"+ childAsk + getHtmlAnalysisSingle(c)
                }
            }
        } else {
            val childListSize = paperPerAnalysisInfor.TypeList[index_A].QuesDetailList[index_B].ChildList.size
            for (c in 0 until childListSize) {
                val sortIndex = getChildListBean(paperPerAnalysisInfor, index_A, index_B, c).ItemList[0].SortIndex
                val sortIndexType = getChildListBean(paperPerAnalysisInfor, index_A, index_B, c).SortIndexType
                val childAsk = getChildListBean(paperPerAnalysisInfor, index_A, index_B, c).ChildAsk
                if (sortIndexType == 0) {
                    if(quesBody.isEmpty()){
                        if(ask.isEmpty()) {
                            ask = "$sortIndex. $childAsk"
                        }else{
                            ask = "$ask<br>$sortIndex. $childAsk"
                        }
                    }else{
                        ask = "$quesBody<br>$sortIndex. $childAsk"
                    }
                } else if (sortIndexType == 1) {
                    ask = "$quesBody<br>$childAsk"
                }
            }
            ask += getHtmlAnalysisAll()

        }

        ask = ask.replace("clickFunction", "Android.clickFunction")
        ask = ask.replace("style=\"display:inline-block;height:20px;text-align:center;text-indent:0;border-bottom:1px solid #333;min-width:70px;",
//                "style=\"display:inline-block;text-align:center;text-indent:0;border-bottom:1px solid #333;min-width:70px;")
                "style=\"border-bottom:1px solid #333;min-width:70px;")

        if (WebStyleUtils.hasTable(ask)) {
            WebStyleUtils.showWebViewCssStyle(activity, rootView!!.WvAsk, ask, false)
        } else {
            WebStyleUtils.showWebViewCssStyle(activity, rootView!!.WvAsk, ask, true)
        }
        rootView!!.WvAsk.addJavascriptInterface(
                JSInterface(
                        activity,
                        WebStyleUtils.returnImageUrlsFromHtml(ask)
                ), "Android"
        )
        rootView!!.WvAsk.webViewClient = object : WebViewClient() {
            override fun onPageFinished(view: WebView, url: String) {
                super.onPageFinished(view, url)
                rootView!!.RlWebLoading.visibility = View.GONE
                WebStyleUtils.setWebImageClick(view, "Android")

                isAddView = true
                handler.sendEmptyMessageDelayed(0, 100)

            }
        }


        rootView!!.WvAsk.setOnScrollChangeListener(object : KWebView.OnScrollChangeListener {
            override fun onPageEnd(l: Int, t: Int, oldl: Int, oldt: Int) {
                Log.e("KWvA", "已经到达地端")
            }

            override fun onPageTop(l: Int, t: Int, oldl: Int, oldt: Int) {
                Log.e("KWvA", "已经到达顶端")
            }

            override fun onScrollChanged(l: Int, t: Int, oldl: Int, oldt: Int) {
                Log.e("KWvA", "=======oldt========$oldt")
                last_Y = oldt
            }
        })

    }


    //JS点击事件处理
    inner class JSInterface(var context: Context, var imageUrls: Array<String>?) {

        @JavascriptInterface
        fun clickFunction(position: String) {
            activity.runOnUiThread {
                //在webview中进行点击选择需要作答的区间
                childVpPosition = AnalysisInforIndexHelp.ItemSortIndex_return_ChildVpIndex(paperPerAnalysisInfor, position)
                handler.sendEmptyMessage(0)
            }
        }

        //java回调js代码，不要忘了@JavascriptInterface这个注解，不然点击事件不起作用
        @JavascriptInterface
        fun openImage(img: String, pos: Int) {
            val paths = ArrayList<String>()
            paths.add(img)
            Log.e("openImage", "$pos========点击了图片=========$img")
            ShowDialogTools.showBigImageDialog(activity, img)
        }
    }

    private fun showBlankView() {

        var kWvHeight = rootView!!.WvAsk.height//获取当前webview控件的高度
        rootView!!.WvAsk.evaluateJavascript(
                "javascript:topHeight('blank$jumpSortIndex')",
                ValueCallback<String?> { value ->
                    val dp = Integer.valueOf(value!!)
                    current_Y = (Math.round(dp * scale) - kWvHeight / 2).toInt()//此处关键，保持被点击的区域处于可见区域中间位置
                    val anim: ObjectAnimator =
                            ObjectAnimator.ofInt(
                                    rootView!!.WvAsk, "scrollY", last_Y, current_Y
                            )
                    anim.setDuration(500).start()
                    last_Y = current_Y
                })

        val childListSize = paperPerAnalysisInfor.TypeList[index_A].QuesDetailList[index_B].ChildList.size
        for (c in 0 until childListSize) {
            val itemListSize = getChildListBean(paperPerAnalysisInfor, index_A, index_B, c).ItemList.size
            for (d in 0 until itemListSize) {
                val state = paperPerAnalysisInfor.TypeList[index_A].QuesAnswerList[index_B].ChildAnswerList[c].ItemList[d].State
                val itemSortIndex = getChildListBean(paperPerAnalysisInfor, index_A, index_B, c).ItemList[d].ItemSortIndex

                var itemAnswer = getChildListBean(paperPerAnalysisInfor, index_A, index_B, c).ItemList[d].ItemAnswer
                itemAnswer = LancooMethod.getNewItemAnswer(itemAnswer, true)
                var stuAnswer = paperPerAnalysisInfor.TypeList[index_A].QuesAnswerList[index_B].ChildAnswerList[c].ItemList[d].StuAnswer
                stuAnswer = LancooMethod.getNewStuAnswer(stuAnswer, true)
                var imagePath = paperPerAnalysisInfor.TypeList[index_A].QuesAnswerList[index_B].ChildAnswerList[c].ItemList[d].ImagePath
//                imagePath = "https://obs-lgresv56pc-yanyi.obs.cn-east-2.myhuaweicloud.com/lgRs/418161523f324d52b246a387edfcd501/82651b85563b4f17a8ced2c48347db1f.jpg"
                var scoreRate = paperPerAnalysisInfor.TypeList[index_A].QuesAnswerList[index_B].ChildAnswerList[c].ItemList[d].ScoreRate
                if (itemSortIndex == jumpSortIndex) {
                    rootView!!.WvAsk.loadUrl("javascript:setBackGroundColor('" + "blank" + itemSortIndex +
                            "','" + "#ceebff" + "','" + "5px" + "','" + "0px solid #ffffff" + "')")
                } else {
                    rootView!!.WvAsk.loadUrl("javascript:setBackGroundColor('" + "blank" + itemSortIndex +
                            "','" + "#00000000" + "','" + "0px" + "','" + "1px solid #848484" + "')")
                }
                showBlankItemAnswer(state,itemSortIndex,imagePath, stuAnswer, itemAnswer,scoreRate)
            }
        }

    }

    private fun showBlankItemAnswer(
            state: Int,
            itemSortIndex: String,
            imagePath: String,
            stuAnswer: String,
            itemAnswer: String,
            scoreRate: Double
    ) {
        var stuAnswerX = stuAnswer
        if (stuAnswer.isEmpty()&&imagePath.isEmpty()) {
            stuAnswerX = "未填写"
        }
        if (scoreRate < 1) {
            if(imagePath.isEmpty()){
                rootView!!.WvAsk.loadUrl(
                        "javascript:CalledByJavaCodeWithPara('" + "blank" + itemSortIndex
                                + "','" + "&nbsp&nbsp"
                                + "<font color=\"#ff0000\">" + stuAnswerX + "</font>"
                                + "<font color=\"#00b30d\">" + "(" + itemAnswer + ")" + "</font>"
                                + "&nbsp&nbsp" + " ')"
                )
            }else {
//                "<div class=\"editor\" style=\"width: %.0lfpx; height: %lf.0px; overflow: auto; text-indent: 0em \"> <img src=\"%@\"></div>"
                //获取图片真正的宽高
                Glide.with(activity)
                        .asBitmap()
                        .load(Ext.OBSINFO?.ServerWithBucket + imagePath).into(object : SimpleTarget<Bitmap?>() {
                    override fun onResourceReady(bitmap: Bitmap, transition: Transition<in Bitmap?>?) {
                        val width: Int = bitmap.width
                        val height: Int = bitmap.width
                        Log.e("GlideAA", "==aa==得到===width====== $width") //900px
                        Log.e("GlideAA", "==bb==得到===height===== $height") //500px

                        if (state == 0) {
                            if(width>screenWidth) {
                                setScanAnswerListener()
                                rootView!!.WvAsk.loadUrl(
                                        "javascript:CalledByJavaCodeWithPara('" + "blank" + itemSortIndex
                                                + "','"
                                                + "<div class=\"editor\" style=\"width:100%; overflow-x:scroll; text-indent: 0em \">"
                                                + "<IMG hspace=2 src=" + Ext.OBSINFO?.ServerWithBucket + imagePath + " style = \"border:2px solid#00000000\" align=left|bottom width=" + width + "px>"
                                                + "</div>"
                                                + "<font color=\"#00b30d\">" + "(" + itemAnswer + ")" + "</font>"
                                                + " ')"
                                )
                            }else{
                                rootView!!.WvAsk.loadUrl(
                                        "javascript:CalledByJavaCodeWithPara('" + "blank" + itemSortIndex
                                                + "','"
                                                + "<body class=\"editor\" style=\"width:100%; overflow-x:scroll; text-indent: 0em \">"
                                                + "<IMG hspace=2 src=" + Ext.OBSINFO?.ServerWithBucket + imagePath + " style = \"border:2px solid#00000000\" align=left|bottom width=" + width + "px>"
                                                + "</body>"
                                                + "<font color=\"#00b30d\">" + "(" + itemAnswer + ")" + "</font>"
                                                + " ')"
                                )
                            }
                        } else {
                            if(width>screenWidth) {
                                setScanAnswerListener()
                                rootView!!.WvAsk.loadUrl(
                                        "javascript:CalledByJavaCodeWithPara('" + "blank" + itemSortIndex
                                                + "','"
                                                + "<div class=\"editor\" style=\"width:100%; overflow-x:scroll; text-indent: 0em \">"
                                                + "<IMG hspace=2 src=" + Ext.OBSINFO?.ServerWithBucket + imagePath + " style = \"border:2px solid#ff0000\" align=left|bottom width=" + width + "px>"
                                                + "</div>"
                                                + "<font color=\"#00b30d\">" + "(" + itemAnswer + ")" + "</font>"
                                                + " ')"
                                )
                            }else{
                                rootView!!.WvAsk.loadUrl(
                                        "javascript:CalledByJavaCodeWithPara('" + "blank" + itemSortIndex
                                                + "','"
                                                + "<body class=\"editor\" style=\"width:100%; overflow-x:scroll; text-indent: 0em \">"
                                                + "<IMG hspace=2 src=" + Ext.OBSINFO?.ServerWithBucket + imagePath + " style = \"border:2px solid#ff0000\" align=left|bottom width=" + width + "px>"
                                                + "</body>"
                                                + "<font color=\"#00b30d\">" + "(" + itemAnswer + ")" + "</font>"
                                                + " ')"
                                )
                            }
                        }
                    }
                })

            }
        } else {
            if(imagePath.isEmpty()) {
                rootView!!.WvAsk.loadUrl(
                        "javascript:CalledByJavaCodeWithPara('" + "blank" + itemSortIndex
                                + "','" + "&nbsp&nbsp&nbsp&nbsp&nbsp"
                                + "<font color=\"#00b30d\">" + stuAnswer + "</font>"
                                + "&nbsp&nbsp&nbsp&nbsp&nbsp" + " ')"
                )
            }else{

                Glide.with(activity).asBitmap().load(Ext.OBSINFO?.ServerWithBucket + imagePath).into(object : SimpleTarget<Bitmap?>() {
                    override fun onResourceReady(bitmap: Bitmap, transition: Transition<in Bitmap?>?) {
                        val width: Int = bitmap.width
                        val height: Int = bitmap.height
                        Log.e("GlideAA", "==cc==得到===width====== $width") //900px
                        Log.e("GlideAA", "==dd==得到===height===== $height") //500px

                        if (state == 0) {
                            if(width>screenWidth) {
                                setScanAnswerListener()
                                rootView!!.WvAsk.loadUrl(
                                        "javascript:CalledByJavaCodeWithPara('" + "blank" + itemSortIndex
                                                + "','"
                                                + "<div class=\"editor\" style=\"width:100%; overflow-x:scroll; text-indent: 0em \">"
                                                + "<IMG hspace=2 src=" + Ext.OBSINFO?.ServerWithBucket + imagePath + " style = \"border:2px solid#00000000\" align=left|bottom width=" + width + "px>"
                                                + "</div>"
                                                + "<font color=\"#00b30d\">" + "(" + itemAnswer + ")" + "</font>"
                                                + " ')"
                                )
                            }else{
                                rootView!!.WvAsk.loadUrl(
                                        "javascript:CalledByJavaCodeWithPara('" + "blank" + itemSortIndex
                                                + "','"
                                                + "<body class=\"editor\" style=\"width:100%; overflow-x:scroll; text-indent: 0em \">"
                                                + "<IMG hspace=2 src=" + Ext.OBSINFO?.ServerWithBucket + imagePath + " style = \"border:2px solid#00000000\" align=left|bottom width=" + width + "px>"
                                                + "</body>"
                                                + "<font color=\"#00b30d\">" + "(" + itemAnswer + ")" + "</font>"
                                                + " ')"
                                )
                            }
                        } else {
                            if(width>screenWidth) {
                                setScanAnswerListener()
                                rootView!!.WvAsk.loadUrl(
                                        "javascript:CalledByJavaCodeWithPara('" + "blank" + itemSortIndex
                                                + "','"
                                                + "<div class=\"editor\" style=\"width:100%; overflow-x:scroll; text-indent: 0em \">"
                                                + "<IMG hspace=2 src=" + Ext.OBSINFO?.ServerWithBucket + imagePath + " style = \"border:2px solid#00b30d\" align=left|bottom width=" + width + "px>"
                                                + "</div>"
                                                + "<font color=\"#00b30d\">" + "(" + itemAnswer + ")" + "</font>"
                                                + " ')"
                                )
                            }else{
                                rootView!!.WvAsk.loadUrl(
                                        "javascript:CalledByJavaCodeWithPara('" + "blank" + itemSortIndex
                                                + "','"
                                                + "<body class=\"editor\" style=\"width:100%; overflow-x:scroll; text-indent: 0em \">"
                                                + "<IMG hspace=2 src=" + Ext.OBSINFO?.ServerWithBucket + imagePath + " style = \"border:2px solid#00b30d\" align=left|bottom width=" + width + "px>"
                                                + "</body>"
                                                + "<font color=\"#00b30d\">" + "(" + itemAnswer + ")" + "</font>"
                                                + " ')"
                                )
                            }
                        }
                    }
                })

            }
        }
    }

    private fun getHtmlAnalysisSingle(index_C: Int): String {
        var itemAnalysis = getChildListBean(paperPerAnalysisInfor, index_A, index_B, index_C).ChildAnalysis
        if (itemAnalysis.isEmpty()) {
            itemAnalysis = activity.getString(R.string.aibk_no_text) //...略
        }

//        var ScreenWidth = DensityUtils.getScreenWidth(activity)
//        ScreenWidth = DensityUtils.px2dp(activity, ScreenWidth.toFloat())
//        itemAnalysis = "<div>\n" +
//                "    <p style=\"width:100;float: left;color:#00afff;\">【答案解析】</p>\n" +
//                "    <div style=\"width: " + (ScreenWidth - 100) + ";float: left;word-wrap: break-word;\">\n" +
//                "      <p>" + itemAnalysis + "</p>\n" +
//                "    </div>\n" +
//                "  </div>"
        itemAnalysis = "<div style=\"color:#00afff;margin-top:10\">【答案解析】 </div>" +
                "<div style=\"color:#848484;margin-left:10;margin-right:10;\">"+itemAnalysis+"</div>"

        return itemAnalysis
    }

    private fun getHtmlAnalysisAll(): String {

        var isHaveItemAnalysis = false
        var ItemAnalysisAll = ""
        val ChildListSize = paperPerAnalysisInfor.TypeList[index_A].QuesDetailList[index_B].ChildList.size
        for (c in 0 until ChildListSize) {
            val SortIndxType = getChildListBean(paperPerAnalysisInfor, index_A, index_B, c).SortIndexType
            if (SortIndxType == 0) {
                var ChildAnalysis = getChildListBean(paperPerAnalysisInfor, index_A, index_B, c).ChildAnalysis
                if (ChildAnalysis.isEmpty()) {
                    ChildAnalysis = activity.getString(R.string.aibk_no_text) //...略
                } else {
                    isHaveItemAnalysis = true
                }
                if (ItemAnalysisAll.isEmpty()) {
                    ItemAnalysisAll = ChildAnalysis
                } else {
                    ItemAnalysisAll = "$ItemAnalysisAll<br>$ChildAnalysis"
                }
            } else if (SortIndxType == 1) {
                val ItemListsize = getChildListBean(paperPerAnalysisInfor, index_A, index_B, c).ItemList.size
                for (d in 0 until ItemListsize) {
                    val SortIndex = getChildListBean(paperPerAnalysisInfor, index_A, index_B, c).ItemList[d].SortIndex
                    var ItemAnalysis = getChildListBean(paperPerAnalysisInfor, index_A, index_B, c).ItemList[d].ItemAnalysis
                    if (ItemAnalysis.isEmpty()) {
                        ItemAnalysis = activity.getString(R.string.aibk_no_text) //...略
                    } else {
                        isHaveItemAnalysis = true
                    }
                    if (ItemAnalysisAll.isEmpty()) {
                        ItemAnalysisAll = "<b>$SortIndex. </b>$ItemAnalysis"
                    } else {
                        ItemAnalysisAll = "$ItemAnalysisAll<br><b>$SortIndex. </b>$ItemAnalysis"
                    }
                }
            }
            if (!isHaveItemAnalysis) {
                ItemAnalysisAll = activity.getString(R.string.aibk_no_text)
            }
        }

//        var ScreenWidth = DensityUtils.getScreenWidth(activity)
//        ScreenWidth = DensityUtils.px2dp(activity, ScreenWidth.toFloat())
//        ItemAnalysisAll = "<div>\n" +
//                "    <p style=\"width:100;float: left;color:#00afff;\">【答案解析】</p>\n" +
//                "    <div style=\"width: " + (ScreenWidth - 100) + ";float: left;word-wrap: break-word;\">\n" +
//                "      <p>" + ItemAnalysisAll + "</p>\n" +
//                "    </div>\n" +
//                "  </div>"
        ItemAnalysisAll = "<div style=\"color:#00afff;margin-top:10\">【答案解析】 </div>" +
                "<div style=\"color:#848484;margin-left:10;margin-right:10;\">"+ItemAnalysisAll+"</div>"

        return ItemAnalysisAll
    }

    override fun onClick(v: View?) {
        when (v?.id) {
            R.id.IvPlayOrPause -> {
                var quesAudioPath = paperPerAnalysisInfor.TypeList[index_A].QuesDetailList[index_B].QuesAudio.Path
                audioPlayer = AudioPlayer(
                        activity, rootView!!.IvPlayOrPause,
                        rootView!!.SeekBarProgress,
                        rootView!!.TvAudioCurrentTime,
                        rootView!!.TvAudioTotalTime,
                        quesAudioPath,
                        AudioPlayer.ParentAudioListener {
                            val audioSpeed = paperPerAnalysisInfor.TypeList[index_A].QuesDetailList[index_B].AudioSpeed
                            audioPlayer!!.setPlaySpeed(audioSpeed.toFloat())
                        })
            }
        }
    }

    //答题卡跳转
    fun fragmentJumpToSortIndex(itemSortIndex: String) {
        childVpPosition = AnalysisInforIndexHelp.ItemSortIndex_return_ChildVpIndex(paperPerAnalysisInfor, itemSortIndex)
        if (isAddView) {
            handler.sendEmptyMessageDelayed(0, 100)
        }
    }

    //答题卡跳转辅助方法
    private val handler = Handler(Handler.Callback { msg ->
        when (msg.what) {
            0 -> {
                jumpSortIndex = AnalysisInforIndexHelp.ChildVpIndex_return_ItemSortIndex(paperPerAnalysisInfor, index_A, index_B, childVpPosition)
                showBlankView()
            }
        }
        false
    })

    override fun setMenuVisibility(menuVisible: Boolean) {
        super.setMenuVisibility(menuVisible)
        pauseAudio()
    }

    //当是扫描作答时调用
    private var isBigImage = false
    private fun setScanAnswerListener(){
        //为了解决viewpager与webview的内部滑动冲突而不得已为之
        if(!isBigImage) {
            val dm = DisplayMetrics()
            val manager: WindowManager = activity.getSystemService(Context.WINDOW_SERVICE) as WindowManager
            manager.defaultDisplay.getMetrics(dm)
            rootView!!.WvAsk.setOnTouchListener(View.OnTouchListener { v, event ->
                when (event.action) {
                    MotionEvent.ACTION_DOWN -> {
                        val point = event.x.toInt()
                        if (point > 0 && point < (DensityUtils.dp2px(activity,screenWidth.toFloat())/ 3 - 1) || point > dm.widthPixels - (DensityUtils.dp2px(activity,screenWidth.toFloat()) / 3) && point < dm.widthPixels) {
                            rootView!!.WvAsk.requestDisallowInterceptTouchEvent(false)
                        } else {
                            rootView!!.WvAsk.requestDisallowInterceptTouchEvent(true)
                        }
                    }
                }
                false
            })
            isBigImage = true
        }
    }

}